package com.study.experiment05.bean;

import java.sql.Connection;
import java.sql.DriverManager;

public class DBConn {
    /**
     * Fields
     */
    private Connection dbConn;
    private String dbUrl = "jdbc:mysql://localhost:3306/servletdemo";
    private String dbUser = "root";
    private String dbPwd = "123456";
    private String err;

    /**
     * Constructor
     */
    public DBConn() {
        err = "";
        dbConn = null;
    }

    /**
     * get connectio method
     *
     * @return a connection to mysql
     */
    public Connection getConn() {

        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            dbConn = DriverManager.getConnection(dbUrl, dbUser, dbPwd);
        } catch (Exception ex) {
            dbConn = null;
            err = ex.toString();
            System.out.println(err);
        }
        return dbConn;

    }

    /**
     * get error message
     *
     * @return error message
     */
    public String getErr() {
        return err;
    }
}
